package ioperations;

import book.Book;
import book.bookList;

import java.util.Scanner;

public class DelOperation implements IOperation {
    public void work(bookList BookList) {
        System.out.println("删除图书......");

        System.out.println("请输入你要删除的书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int useSize = BookList.getUsesize();

        int pos = -1;
        int i =0;
        for ( i = 0; i < useSize; i++) {
            Book book = BookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("找到了这本书");
                pos = i;
                break;
            }
            if(i == useSize){
            System.out.println("没有你要删除的书");
            return;
            }

            //这里开始删除
            for (int j = pos; j < useSize - 1 ; j++) {
                Book book1 = BookList.getBook(j + 1);

                BookList.setBook(j,book1);
                System.out.println("删除成功");
            }

        }
    }
}